package com.jhecis.controller;

import com.jhecis.dto.ApiData;
import com.jhecis.dto.ScriptContent;
import com.jhecis.common.JsEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/JavaScript")
@RestController
public class JavaScriptController {

    @Autowired
    private JsEngine jsEngine;

    @PostMapping("/Convert")
    public ApiData Convert(@RequestBody ScriptContent script){
        ApiData res=new ApiData();
        System.out.println("接收到的参数");
        System.out.println(script.toString());
        String returnData="";
        try{
            returnData=  jsEngine.execJs(script);
            res.setData(returnData);
        }catch (Exception e){
         //记录日志吧
        }
       return res;
    }
}
